// pages/server/server.js
Page({
  data: {
    activeIndex: '0',
    data2: null,
    data1: null,
    longitude: null,
    latitude: null,
  },
  onLoad: function (options) {
    // console.log(options)
    var that = this
    that.setData({
      activeIndex: options.ID,
      latitude: options.latitude,
      longitude: options.longitude
    })
    // 页面初始化 options为页面跳转所带来的参数
    wx.request({
      url: "http://1.aiym.applinzi.com/aiyouwai.php",
      data: {
        type: "firstPage"
      },
      header: { "content-type": "application/json" },
      success: function (res) {
        that.setData({
          data2: res.data
        })
      }
    })
    console.log(that.data.data2)
    var content = options.name ? options.name : this.data.data;
    // 右侧加载
    wx.request({
      url: "http://1.aiym.applinzi.com/aiyouwai.php",
      data: {
        type: "getGoods",
        paras: {
          goodType: content
        }
      },
      header: { "content-type": "application/json" },
      success: function (res) {
        // console.log(res.data)
        that.setData({
          data1: res.data,
        })
      }
    })

  },
  // 点击更换右侧内容
  click: function (event) {
    var index = event.currentTarget.dataset.index;
    this.setData({
      activeIndex: index
    })

    var that = this;
    // console.log(event.currentTarget.dataset.id)
    var content = event.currentTarget.dataset.name;
    wx.request({
      url: "http://1.aiym.applinzi.com/aiyouwai.php",
      data: {
        type: "getGoods",
        paras: {
          goodType: content,
        }
      },
      header: { "content-type": "application/json" },
      success: function (res) {
        console.log(res.data)
        that.setData({
          data1: res.data,
        })
      }
    })
  },
  // 点击服务标签获取服务id获取服务价格然后进行本地缓存进行页面跳转进入信息发布页面
  submit: function (event) {
    // 获取服务id服务价格进行session缓存进行参数传

    if (!this.data.uid) {
      wx.showModal({
        content: '请您先登录',
        showCancel: false,
        success: function (res) {
          wx.navigateTo({
            url: '../login/login',
          })
        }
      });
    } else {
      wx.navigateTo({
        url: '../message/message?gid=' + event.currentTarget.dataset.gid + '&longitude=' + this.data.longitude + '&latitude=' + this.data.latitude + "&uid=" + this.data.uid.uid,
      })
    }

  },
  onShow: function () {
    var that = this;
    // 页面显示
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        that.setData({
          uid: res.data
        })
      },

    })
  },

})